<template>
  <div class="layout-all">
    <el-button type="primary" size="small" icon="el-icon-edit" @click="copy">复制全部优惠券</el-button>
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%; margin-top: 50px;"
      >
        <el-table-column
          align="center"
          prop="code"
          label="优惠券"
          width="200"
        />
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
export default {
  name:'couponCode',
  props:['id'],
  data() {
    return {

      value: "",
      searchWhere: {
        title: "",
      },
      tableData: [],
      total: 0,
      current_page: 1,
      per_page: 14,
    };
  },
  mounted() {
    this.onSearch();
  },
  methods: {
    copy(){
      const form = {};
      form.all = 1;
      form.id = this.id;
      this.get("/shop/Coupon/get_code_list", form, "POST").then((e) => {
        this.$copy(e.list.join("\n"))
        this.$msg_ok('success','复制成功')
      });
    },
    // 查询
    handleSizeChange(val) {
      this.onSearch();
    },
    handleCurrentChange(val) {
      this.current_page = val;
      this.onSearch();
    },
    onSearch() {
      const form = {};
      form.page = this.current_page;
      form.id = this.id;
      this.get("/shop/Coupon/get_code_list", form, "POST").then((e) => {
        this.tableData = e.list.data;
        this.per_page = e.list.per_page;
        this.total = e.list.total;
        this.current_page = e.list.current_page;
      });
    },
  },
};
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
